package com.baizhi.action;

import com.baizhi.entity.Commit;
import com.baizhi.entity.Title;
import com.baizhi.service.CommitService;
import com.baizhi.service.CommitServiceImpl;
import com.baizhi.service.TitleService;
import com.baizhi.service.TitleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class ShowBlogArticleAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");


        TitleService ts = new TitleServiceImpl();
        Title title = new Title();
        title.setTitle(name);

        Title title1 = ts.queryByTitle(title);
        req.setAttribute("title1",title1);

        HttpSession session = req.getSession();
        CommitService cs = new CommitServiceImpl();
        Commit commit1 = new Commit();
        commit1.setTitle(name);
        List<Commit> commits = cs.showAll(commit1);
        System.out.println("获取评论"+commits);
        req.setAttribute("commits",commits);
        session.setAttribute("commits",commits);



        req.getRequestDispatcher("/blog_article.jsp").forward(req,resp);
    }
}
